package team.knowers.qzh.qzhadmin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import team.knowers.qzh.qzhadmin.dao.entity.CourseContentDO;
import team.knowers.qzh.qzhadmin.dao.mapper.CourseContentMapper;
import team.knowers.qzh.qzhadmin.dto.resp.AllCourseContentRespDTO;
import team.knowers.qzh.qzhadmin.service.CourseContentAdminService;

import java.util.ArrayList;
import java.util.List;

@Service
@AllArgsConstructor
public class CourseContentAdminServiceImpl extends ServiceImpl<CourseContentMapper, CourseContentDO> implements CourseContentAdminService {
    @Override
    public List<AllCourseContentRespDTO> shouCourseContent(Long id) {
        LambdaQueryWrapper<CourseContentDO> queryWrapper= Wrappers.lambdaQuery(CourseContentDO.class)
                .eq(CourseContentDO::getSectionId,id)
                .eq(CourseContentDO::getDelFlag,0)
                .orderByAsc(CourseContentDO::getOrder);
        List<CourseContentDO> courseContentDOS=baseMapper.selectList(queryWrapper);
        List<AllCourseContentRespDTO> allCourseContentRespDTOS=new ArrayList<>();
        for(CourseContentDO courseContentDO:courseContentDOS)
        {
            AllCourseContentRespDTO allCourseContentRespDTO=new AllCourseContentRespDTO();
            allCourseContentRespDTO.setContent(courseContentDO.getContent());
            allCourseContentRespDTO.setId(courseContentDO.getId());
            allCourseContentRespDTO.setOrder(courseContentDO.getOrder());
            allCourseContentRespDTOS.add(allCourseContentRespDTO);
        }
        return allCourseContentRespDTOS;
    }

}
